<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="4" :lg="4" :md="4" :sm="24">
            <a-form-item label="商家名称">
              <a-input placeholder="请输入商家名称" v-model="queryParam.merchName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="4" :md="4" :sm="24">
            <a-form-item label="商家状态">
               <a-select v-model="queryParam.merchStatus" placeholder="请输入商家状态">
                <a-select-option value="">请选择</a-select-option>
                <a-select-option value="1">启用</a-select-option>
                <a-select-option value="0">停用</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        
            <a-col :xl="4" :lg="4" :md="4" :sm="24">
              <a-form-item label="是否首推">
                 <a-select v-model="queryParam.merchIndexFlag" placeholder="请输入是否首推">
                <a-select-option value="">请选择</a-select-option>
                <a-select-option value="1">是</a-select-option>
                <a-select-option value="0">否</a-select-option>
              </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="4" :md="4" :sm="24">
              <a-form-item label="行业分类">
                 <a-select v-model="queryParam.merchCategory"  placeholder="请选择行业分类">
                  <a-select-option v-for="obj in parentData" :key="obj.value"  :value="obj.value">{{ obj.text }}</a-select-option>
                 </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="4" :md="4" :sm="24">
              <a-form-item label="所属城市">
                <j-dict-select-tag v-model="queryParam.merchCity" placeholder="请选择所属城市" dict-code="merch_citys"/>
              </a-form-item>
            </a-col>
         
          <a-col :xl="4" :lg="4" :md="4" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">注册商家</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
         <template slot="imgSlotBase64" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无商家图片</span>
          <img v-else :src="getImgView1(text)" height="40px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a @click="handleDetail(record)">查看详情</a>
          <a-divider type="vertical" />
          <a @click="viewCoupon(record)">查看优惠券</a>
          <a-divider type="vertical" />
          <a @click="viewCheckCoupon(record)">核销记录</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>

    <adh-merch-info-modal ref="modalForm" @ok="modalFormOk"/>
    <coupon-list-modal ref="modalCoupon" />
   <check-list-modal ref="modalCheckCoupon" />
  </a-card>
</template>

<script>
  import { postAction,getAction } from '@/api/manage'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import AdhMerchInfoModal from './modules/AdhMerchInfoModal'
  import CouponListModal from './modules/CouponListModal'
  import CheckListModal from './modules/CheckListModal'
  import '@/assets/less/TableExpand.less'

  export default {
    name: "AdhMerchInfoList",
    mixins:[JeecgListMixin],
    components: {
      AdhMerchInfoModal,
      CouponListModal,
      CheckListModal
    },
    data () {
      return {
        description: '商家管理管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'商家ID',
            align:"center",
            ellipsis:true,
            width:100,
            dataIndex: 'id'
          },
          {
            title:'商家名称',
            align:"center",
            ellipsis:true,
            width:200,
            dataIndex: 'merchName'
          },
          {
            title:'行业分类',
            align:"center",
            width:80,
            dataIndex: 'merchCategoryName',
          },
          {
            title:'所属城市',
            align:"center",
            dataIndex: 'merchCity'
          },
           {
            title:'联系方式',
            align:"center",
            width:80,
            dataIndex: 'merchConcat',
            customRender:(text,row,index)=>{
                return row.merchConcat+" "+row.merchPhone
             }
          },
          {
            title:'LOGO',
            align:"center",
            dataIndex: 'merchLogo',
            ellipsis:true,
            scopedSlots: { customRender: 'imgSlot' }
          },
          //  {
          //   title:'商家图片',
          //   align:"center",
          //   dataIndex: 'merchIndexImg',
          //    ellipsis:true,
          //   scopedSlots: { customRender: 'imgSlot' }
          // },
          // {
          //   title:'营业时间',
          //   align:"center",
          //   width:120,
          //   dataIndex: 'merchStartTime',
          //   customRender:(text,row,index)=>{
          //       return row.merchDays+""+ row.merchStartTime+"至"+row.merchEndTime
          //    }
          // },
          {
            title:'商家二维码',
            align:"center",
            dataIndex: 'qrCode',
            scopedSlots: { customRender: 'imgSlotBase64' }
          },
          {
            title:'是否首推',
            align:"center",
             width:80,
            dataIndex: 'merchIndexFlag',
            customRender:(text)=>{
               if(text=='1'){
                 return "是"
               }else{
                  return "否"
               }
             }
          },
           {
            title:'商户状态',
            align:"center",
            width:80,
            dataIndex: 'merchStatus',
             customRender:(text)=>{
               if(text=='1'){
                 return "已启用"
               }else{
                  return "已停用"
               }
             }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:330,
            scopedSlots: { customRender: 'action' },
          }
        ],
        parentData:[],
        url: {
          parentData:"/adh/shopCategory/queryParentData",
          list: "/merch/adhMerchInfo/list",
          delete: "/merch/adhMerchInfo/delete",
          deleteBatch: "/merch/adhMerchInfo/deleteBatch",
          exportXlsUrl: "/merch/adhMerchInfo/exportXls",
          importExcelUrl: "merch/adhMerchInfo/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
        couponModalVisible:false
      }
    },
    created() {
      this.getSuperFieldList();
      this.queryParentData();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      getImgView1:function(text){
        return "data:image/png;base64,"+text;
      },
      viewCoupon:function(record){
          this.$refs.modalCoupon.showModel(record);
      },
      viewCheckCoupon:function(record){
          this.$refs.modalCheckCoupon.showModel(record);
      },
      queryParentData(){
        var that = this;
        getAction(this.url.parentData,{}).then((res)=>{
        if(res.success){
            that.parentData = res.result;
          }
        })
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
         fieldList.push({type:'string',value:'merchName',text:'商家名称',dictCode:''})
         fieldList.push({type:'string',value:'merchLogo',text:'商家LOGO',dictCode:''})
         fieldList.push({type:'string',value:'merchAddress',text:'商家地址',dictCode:''})
         fieldList.push({type:'string',value:'merchAddressDetail',text:'商家地址详情',dictCode:''})
         fieldList.push({type:'string',value:'merchTags',text:'商家标签',dictCode:''})
         fieldList.push({type:'string',value:'merchIndexImg',text:'商家门头照',dictCode:''})
         fieldList.push({type:'string',value:'merchStartTime',text:'营业开始时间',dictCode:''})
         fieldList.push({type:'string',value:'merchEndTime',text:'营业结束时间',dictCode:''})
         fieldList.push({type:'string',value:'merchDays',text:'营业周期',dictCode:''})
         fieldList.push({type:'string',value:'merchPhone',text:'商户联系电话',dictCode:''})
         fieldList.push({type:'string',value:'merchStatus',text:'商户状态',dictCode:''})
         fieldList.push({type:'string',value:'merchSort',text:'商户排序',dictCode:''})
         fieldList.push({type:'string',value:'merchIndexFlag',text:'是否首页显示',dictCode:''})
         fieldList.push({type:'string',value:'merchCategory',text:'商家分类',dictCode:''})
         fieldList.push({type:'string',value:'merchBrand',text:'商家品牌',dictCode:''})
         fieldList.push({type:'Text',value:'merchDesc',text:'商家简介',dictCode:''})
         fieldList.push({type:'string',value:'merchConcat',text:'商家联系人',dictCode:''})
         fieldList.push({type:'string',value:'merchCity',text:'所属城市',dictCode:'merch_citys'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>